import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/widgets/dialog/xindong_base_alert.dart';

/// 选择栏 - 左右按钮
class XinDongAlertOptions extends StatelessWidget {
  final String? title; // 标题
  final String content; // 内容
  final String leftName; // 左侧按钮名称
  final String rightName; // 右侧按钮名称
  final Color? rightColor; // 右侧按钮字体颜色
  final Color? leftColor; // 左侧按钮字体颜色
  final VoidCallback? onTapLeft;
  final VoidCallback? onTapRight;

  // 构造函数
  const XinDongAlertOptions(
      {Key? key,
      required this.content,
      required this.leftName,
      required this.rightName,
      this.title,
      this.leftColor,
      this.rightColor,
      this.onTapRight,
      this.onTapLeft})
      : super(key: key);

  XinDongAlertOptions.show({
    super.key,
    this.title,
    required this.content,
    required this.leftName,
    required this.rightName,
    this.leftColor = DZColors.titleColor,
    this.rightColor = DZColors.mainBlueColor,
    this.onTapLeft,
    this.onTapRight,
  }) {
    showAlertDialog(
        alert: XinDongAlertOptions(
      title: title,
      content: content,
      leftName: leftName,
      rightName: rightName,
      leftColor: leftColor,
      rightColor: rightColor,
      onTapRight: onTapRight,
      onTapLeft: onTapLeft,
    ));
  }

  @override
  Widget build(BuildContext context) {
    return XinDongBaseDialog(
      hideWhenTouchOutside: true,
      body: Container(
        margin: const EdgeInsets.only(left: 42, right: 42, bottom: 24),
        padding: const EdgeInsets.only(left: 24, right: 24, top: 16),
        width: screenWidth,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(8), color: DZColors.dialog),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            /// 标题
            TextUtil.isEmpty(title)
                ? const SizedBox()
                : Text(
                    title!,
                    style: const TextStyle(color: DZColors.titleColor, fontSize: 18, fontWeight: FontWeight.w500),
                  ),

            /// 内容
            Container(
              padding: EdgeInsets.fromLTRB(20, TextUtil.isEmpty(title) ? 0 : 10, 20, 20),
              child: Text(
                content,
                style: const TextStyle(color: DZColors.contentColor, fontSize: 16),
              ),
            ),
            Container(height: 0.5, color: DZColors.dividerColor),
            SizedBox(
              height: kCellHeight,
              width: double.infinity,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  /// 左侧按钮
                  Expanded(
                    child: TextButton(
                      onPressed: () {
                        Navigator.pop(context, false);
                        if (onTapLeft != null) {
                          onTapLeft!();
                        }
                      },
                      child: Text(
                        leftName,
                        style: TextStyle(
                            fontSize: 16, fontWeight: FontWeight.normal, color: leftColor ?? DZColors.placeholderColor),
                      ),
                    ),
                  ),
                  Container(width: 0.5, color: DZColors.dividerColor),

                  /// 右侧按钮
                  Expanded(
                    child: TextButton(
                      onPressed: () {
                        Navigator.pop(context, true);
                        if (onTapRight != null) {
                          onTapRight!();
                        }
                      },
                      child: Text(
                        rightName,
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.normal,
                          color: rightColor ?? DZColors.mainBlueColor,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
